package org.vergil.core.designpattern.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by vergil on 17-3-24.
 */
public class Client {
    public static void main(String args[]) {
        List products = new ArrayList();
        products.add("java");
        products.add("C#");
        products.add("C");
        products.add("python");
        products.add("js");

        AbstractObjectList list;
        AbstractIterator iterator;

        list = new ProductList(products); //创建聚合对象
        iterator = list.createIterator();   //创建迭代器对象

        System.out.println("正向遍历：");
        while(!iterator.isLast()) {
            System.out.print(iterator.getNextItem() + "，");
            iterator.next();
        }
        System.out.println();
        System.out.println("-----------------------------");
        System.out.println("逆向遍历：");
        while(!iterator.isFirst()) {
            System.out.print(iterator.getPreviousItem() + "，");
            iterator.previous();
        }
    }
}
